﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import Events.*;
    import Classes.*;

    public class WhatIsThisPopup extends SWFDialog {

        public static const YES:int = 1;
        public static const NO:int = 0;

        public static var describeDialogOpen:Boolean = false;

        private var m_window:MovieClip;
        private var m_iconLoader:Loader;
        private var m_message:String;
        private var m_closeCallback:Function;
        private var m_accept:GenericButton;
        private var m_reject:GenericButton;
        private var m_item:XML;

        public function WhatIsThisPopup(_arg1:XML, _arg2:Function=null){
            this.m_item = _arg1;
            m_dialogAsset = "assets/dialogs/FV_mysteryBox.swf";
            describeDialogOpen = true;
            super();
            if (_arg2 != null){
                this.m_closeCallback = _arg2;
                addEventListener(GenericPopupEvent.SELECTED, _arg2);
            };
        }
        protected function canBuy():Boolean{
            var _local1:Boolean;
            switch (this.m_item.@unlock.toString()){
                case Item.UNLOCK_LEVEL:
                    if (Global.player.checkLevel(this.m_item.requiredLevel)){
                        _local1 = true;
                    };
                    break;
                case Item.UNLOCK_NEIGHBOR:
                    if (Global.player.checkNeighbors(this.m_item.minNeighbors)){
                        _local1 = true;
                    };
                    break;
                case Item.UNLOCK_PERMITS:
                    if (ExpansionManager.instance.hasEnoughPermits()){
                        _local1 = true;
                    };
                    break;
                default:
                    _local1 = true;
            };
            return (_local1);
        }
        override protected function onLoadComplete():void{
            var _local1:Array = [];
            this.m_window = (m_loader.content as MovieClip);
            if (this.canBuy()){
                this.m_accept = new GenericButton(this.m_window.mysteryBox_mc.buy_bt, this.onAccept);
                this.m_accept.text = ZLoc.t("Dialogs", "Buy");
            } else {
                this.m_window.mysteryBox_mc.buy_bt.visible = false;
            };
            this.m_reject = new GenericButton(this.m_window.mysteryBox_mc.cancel_bt, this.onCancel);
            this.m_reject.text = ZLoc.t("Dialogs", "Cancel");
            var _local2:String = this.m_item.@name.toString();
            _local2 = _local2.replace("_cash", "");
            this.m_window.mysteryBox_mc.title_tf.text = ZLoc.t("Dialogs", (_local2 + "Title"));
            this.m_window.mysteryBox_mc.body_tf.text = ZLoc.t("Dialogs", (_local2 + "Message"));
            addChild(this.m_window);
        }
        protected function onAccept(_arg1:MouseEvent):void{
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, YES));
            if (this.m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, this.m_closeCallback);
            };
            this.close();
        }
        protected function onCancel(_arg1:MouseEvent):void{
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, NO));
            if (this.m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, this.m_closeCallback);
            };
            this.close();
        }
        override public function close():void{
            describeDialogOpen = false;
            super.close();
        }

    }
}//package Display 
